package com.example.springdemo5;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/login")
public class LoginController {
    @RequestMapping("/check")
    public boolean check(String username, String password, HttpSession session) {
        if(!StringUtils.hasLength(username) || !StringUtils.hasLength(password)) {
            return false;
        }
        //检查账号和密码是否正确
        String USERNAME = "zhangsan";
        String PASSWORD = "123456";
        if(USERNAME.equals(username) && PASSWORD.equals(password)) {
            //存储到Session中
            session.setAttribute("username", "zhangsan");
            return true;
        }
        return false;
    }
    @RequestMapping("/index")
    public String index(HttpSession session) {
        String username = (String)session.getAttribute("username");
        return username;
    }
}
